<?php
class Gallery extends GallerysAppModel {

	var $name = 'Gallery';
	var $useTable = 'galleries';
	var $validate = array(
		'title' => array('notempty'),
		'descripcion' => array('notempty')
	);
	var $hasOne =array(
		'Image' => array(
			'className' => 'Images.Image',
			'foreignKey' => 'owner_id',
			'conditions' => 'Image.model = "Gallery"',
			'fields' => '',
			'order' => ''
		)
	);
	
	
	function get_images($limit = 0){	
		$gal = $this->find('first',array('order'=>'Gallery.id DESC'));
		$gal['Image'] = $this->Image->explode_images($gal['Image']);
		$gal2 = $gal;
		$gal2['Image']['files'] = array();
		for ($i=0; $i < $limit ; $i++){
			if (isset($gal['Image']['files'][$i])){
				$gal2['Image']['files'][] = $gal['Image']['files'][$i];
			}else{
				break;
			}
		}
		return $gal2;
	}
}
?>